<?php

namespace app\store\controller\agent;

use app\store\controller\BaseController;
use app\store\service\AgentService;
use app\store\service\OfflineShopService;
use app\store\service\UserService;
use think\facade\View;

class AgentController extends BaseController
{
    /**
     * 待审核列表
     */
    public function index()
    {   

        $param = $this->request->param();

        $agentService = new AgentService();
        $list = $agentService->auditList($param);
        // print_r($list);exit;
        return View::fetch('',['list' => $list]);
    }

    /**
     * 审核通过
     */
    public function agree()
    {
        $id = $this->request->param('id/d');
        $agentService = new AgentService();
        $row = $agentService->findOne($id);
        
        if (empty($row)) {
            return json(['code' => 0, 'msg' => '未找到申请信息!']);
        }

        if ($row['status'] != 1) {
            return json(['code' => 0, 'msg' => '已经审核，请勿重复操作!']);
        }

        $rst = $agentService->auditRst($id, 1, $row);
        return $rst ? json(['code' => 1, 'msg' => '审核成功!']):json(['code' => 0, 'msg' => '审核失败!']);
    }

    /**
     * 审核拒绝
     */
    public function refused(){
       
        $id = $this->request->param('id/d');
        $agentService = new AgentService();
        $row = $agentService->findOne($id);
        
        if (empty($row)) {
            return json(['code' => 0, 'msg' => '未找到申请信息!']);
        }

        if ($row['status'] != 1) {
            return json(['code' => 0, 'msg' => '已经审核，请勿重复操作!']);
        }

        $rst = $agentService->auditRst($id, 2, $row);
        return $rst ? json(['code' => 1, 'msg' => '拒绝成功!']):json(['code' => 0, 'msg' => '拒绝失败!']);

    }

    /**
     * 代理列表
     */
    public function list()
    {   

        $param = $this->request->param();

        $agentService = new AgentService();
        $list = $agentService->list($param);
        // print_r($list);exit;
        return View::fetch('',['list' => $list]);
    }

    // public function option()
    // {
    //     $param = $this->request->param();

    //     $storeUserService = new UserService();
    //     $list = $storeUserService->getUserList($param);

    //     View::engine()->layout(false);

    //     return View::fetch('',['list' => $list]);
    // }

    // /**
    //  * 更新店铺状态
    //  */
    // public function setStatus()
    // {
    //     $param = $this->request->post();
    //     $rst = OfflineShopService::updateStatus($param);
    //     if ($rst) {
    //         return json(['code' => 1, 'msg' => '更新成功!']);
    //     } else {
    //         return json(['code' => 0, 'msg' => '更新失败!']);
    //     }
    // }


    // /**
    //  * 更新推荐店铺
    //  */
    // public function switch()
    // {
    //     $param = $this->request->post();
    //     $rst = OfflineShopService::updateTJ($param);
    //     if ($rst) {
    //         return json(['code' => 1, 'msg' => '更新成功!']);
    //     } else {
    //         return json(['code' => 0, 'msg' => '更新失败!']);
    //     }
    // }

    // public function editHs()
    // {
    //     $id = $this->request->param('id/d');
    //     $StoreUserService = new OfflineShopService();
    //     $row = $StoreUserService->findSHOne($id);
    //     // print_r($row['bg_img']);
    //     return View::fetch('edit',['row' => $row]);
    // }

    // public function edit()
    // {
    //     $id = $this->request->param('id/d');
    //     $StoreUserService = new OfflineShopService();
    //     $row = $StoreUserService->findOne($id);
    //     // print_r($row['bg_img']);
    //     return View::fetch('',['row' => $row]);
    // }

    // public function update()
    // {
    //     $param = $this->request->param();
    //     $id = $this->request->param('id/d');
    //     $StoreUserService = new OfflineShopService();
    //     $row = $StoreUserService->findOne($id);
    //     if(empty($row) ) {
    //         return json(['code' => 0, 'msg' => '未找到指定内容!']);
    //     }
    //     if ($row['status'] !=1) {
    //         return json(['code' => 0, 'msg' => '未找到指定内容!']);
    //     }
    //     if (isset($param['status']) && $param['status']) {
    //         $rst = $StoreUserService->auditShop($param['status'], $id, $row['uid']);
    //         if (!$rst) {
    //             return json(['code' => 0, 'msg' => '审核失败!']);
    //         }
    //     }
    //     return json(['code' => 1, 'msg' => '操作成功!']);
    // }


    
}